package sk.naive.talker.command;

import sk.naive.talker.*;
import sk.naive.talker.message.*;
import sk.naive.talker.persistence.*;

import java.util.Collection;
import java.util.logging.Logger;
import java.rmi.RemoteException;

/**
 * Command dispatcher is intermediator between talker and command itself.
 * <p>
 * This layer of indirection can perform some permission decisions. Another
 * task of dispatcher is to find command specified by its name/string/shorthand.
 *
 * @author <a href="mailto:richter@bgs.sk">Richard Richter</a>
 * @version $Revision: 1.21 $ $Date: 2005/02/16 19:27:20 $
 */
public interface CommandDispatcher {
	/**
	 * Returns collection of all commands.
	 * <p>
	 * Order determines result of search - suggested is natural String
	 * ordering. Eg. if "shout" is before "say" for "s" shorthand command
	 * "shout" is preferred.<br />
	 * Command returns even unconfigured commands (their
	 *
	 * @see sk.naive.talker.util.Utils#findFirstInCollection(java.lang.String, java.util.Collection, boolean)
	 *
	 * @return collection of all commands ordered with respect to searching utilities
	 */
	public Collection<CommandProxy> getCommands();

	/**
	 * Subset of all commands available for specified user.
	 * <p>
	 * Order should be the same like in getCommands().
	 * @see #getCommands()
	 *
	 * @param u user
	 * @return collection of commands available for user
	 */
	public Collection<String> getAvailableCommands(User u);

	/**
	 * Process command with specified parameters for specified user.
	 * <p>
	 * Main task of this method is to find command in collection of
	 * commands available for this user. Some permission decisions can
	 * also be made.
	 *
	 * @see #getAvailableCommands
	 *
	 * @param cmdLine (potentially shorthand) commmand string with all parameters
	 * @param user user issuing command
	 * @throws CommandException thrown if command fails for any reason
	 * @throws RemoteException
	 */
	void process(String cmdLine, User user)
		throws CommandException,
		RemoteException;

	/**
	 * Process command with specified parameters for specified user.
	 * <p>
	 * Main task of this method is to find command in collection of
	 * commands available for this user. Some permission decisions can
	 * also be made.
	 *
	 * @see #getAvailableCommands
	 *
	 * @param cmd (potentially shorthand) commmand string
	 * @param u user issuing command
	 * @param param rest of the command string
	 * @throws CommandException thrown if command fails for any reason
	 * @throws RemoteException
	 */
	public void process(String cmd, User u, String param)
		throws CommandException,
		RemoteException;

	/**
	 * Returns logger of this command dispatcher.
	 * <p>
	 * This logger is available for command if it has need to log something.
	 *
	 * @return command dispatcher's logger
	 */
	public Logger getLogger();

	/**
	 * Returns message factory of this command dispatcher.
	 * <p>
	 * Any message creation in command should use this message factory.
	 *
	 * @return command dispatcher's message factory
	 */
	public MessageFactory getMessageFactory();

	public TextPersistence textPersistence() throws PersistenceException;

	public Talker getTalker();

	public UserFinder getUserFinder();

	public BoardFinder boardFinder();

	public LocationFinder locationFinder();

	public ThingFinder thingFinder();

	ReloadableMessageFactory getHelpMessages();
}